package lv.servidordisqueria.persistencia;

import java.sql.Connection;
import java.sql.DriverManager;

public class ConeccionBaseDatos {

	private static final String USER = "root";
	private static final String PASSWORD = "riverplate";
	private static final String URL = "jdbc:mysql://localhost/disqueria";
	private static final String DRIVER = "org.gjt.mm.mysql.Driver";
	
	private static ConeccionBaseDatos instance = null;
	private Connection conn;
	
	private ConeccionBaseDatos() {
		conn = null;
        try {
            Class.forName(DRIVER).newInstance();
            conn = DriverManager.getConnection(URL, USER, PASSWORD);
            System.out.println ("Database connection established");
        } catch (Exception e) {
            System.err.println ("Cannot connect to database server");
        }
	}

	public static ConeccionBaseDatos getInstance() {
		if(instance == null) {
			instance = new ConeccionBaseDatos();
		}
		return instance;
	}
	
	public Connection getConnection() {
        return conn;
	}
}
